home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TPUG - Toronto PET Users Group
/
TPUG Users Group CD
/
TPUG Users Group CD.iso
/
AMIGA
/
AMICUS
/
AMICUS04.ADF
/
C
/
geltools.c
< prev
next >
Wrap
C/C++ Source or Header
|
1985-11-03
|
26KB
|
644 lines
/* geltools.c */
/* NOTE: don't try to use vsprites until system software V1.1 becomes
available. This tool works to do bobs, but not vsprites until 1.1.
(system bug corrected).
*/
/*
author: Rob Peck 9/85. Will eventually cover AnimObs and AnimComps
but not yet.
also note that NewGelList can be merged directly into
ReadyGels (next version will do so). No need to have
separate.
*/
/* ***********************************************************************
this file is a collection of tools which are used with the vsprite and
bob software. It contains the following:
ReadyGels( *gelsinfo, *rastport )
NewGelList( *gelsinfo )
PurgeGels( *gelsinfo )
struct Bob MakeBob(bitwidth,lineheight,imagedepth,*image,pfdepth,
planePick,planeOnOff,x,y)
DeleteBob( &Bob );
struct VSprite MakeVSprite(lineheight,*image,*colorset,x,y,
width,imagedepth,flags);
DeleteVSprite( &VSprite );
ReadyGels sets up the defaults of the gel system by initializing the
GelsInfo structure you provide. It uses information in your
RastPort structure to establish boundary collision defaults at
the outer edges of the raster. It also links together the
GelsInfo and the RastPort which you provide.
NewGelList allocates space for two dummy virtual sprite structures
and calls InitGels. You must already have run LoadView and
ReadyGels before NewGelList is called.
PurgeGels deallocates all memory which ReadyGels and NewGelList have
allocated. The system will crash if you have not used these
routines to allocate the space (you cant deallocate something
which you havent allocated in the first place).
MakeVSprite allocates enough space for and inits a normal vsprite.
DeleteVSprite deallocates the memory it used.
MakeBob initializes a standard bob and allocates as much memory as is needed
for a normal bob and its vsprite structure, links them together.
To find the associated vsprite, look at the back-pointer (see the
routine doc itself).
DeleteBob deallocates the memory it used.
******************************************************************* */
/* user passes a pointer to his GelsInfo structure which he wants to init,
along with a pointer to his IVPArgs. Default init places the topmost
bottommost etc at the outermost boundaries of the users rastport parameters
*/
ReadyGels(g, r)
struct RastPort *r;
struct GelsInfo *g;
{
WORD *lastcolors; /* pointer to an array of 8 pointers to the last
colors assigned to a hardware sprite */
WORD *nextlines; /* pointer to an array of 8 words which are used
to keep track of the last lines of each sprite */
struct CollTable *collHandler;
/* pointer to the collision handler table */
/* this is a table of pointers to the routines which should
be performed when DoCollision senses a collision. This
declaration may not be necessary for a basic vsprite with
no collision detection implemented, but then it makes for
a complete example */
printf("\nEntered ReadyGels\n");
lastcolors = (WORD *)AllocMem(sizeof(LONG) * 8,
MEMF_PUBLIC+MEMF_CLEAR);
if(lastcolors == NULL)
printf("\nNo memory for lastcolors\n");
/* *******************************************************************
In the lastcolors pointer array, the system will store
a pointer to the color definitions most recently used
by the system. .... as a reminder, virtual sprites can
be assigned to any of the real hardware sprites which
may be available at the time. The vsprite colors will
be written into the hardware sprite register set for
the hardware sprite to which that vsprite is assigned.
This pointer array contains one pointer to the last
set of three colors (from the vsprite structure *sprColors)
for each hardware sprite.
As the system is scanning to determine which hardware
sprite should next be used to represent a vsprite, it
checks the contents of this array. If a hardware sprite
is available and already has been assigned this set of
colors, no color assignment is needed, and therefore
no color change instructions will be generated for the
copper list.
If all vsprites use a different set of sprColors, (pointers
to sprColors are different for all vsprites), then there
is a limit of 4 vsprites on a horizontal line. If, on
the other hand, you define, lets say 8 vsprites, with
1 and 2 having the same sprColors, 3 and 4 the same as
each other, 5 and 6 the same as each other, and 7 and 8
also having the same vsprite colors, then you will be
able to have all 8 vsprites on the same horizontal line.
In this case, you will be able to put all 8 vsprites on
the same horizontal line. The reason this helps is that
the system hardware shares the color registers between pairs
of hardware sprites. The system thus has enough resources
to assign all vsprites to hardware sprites in that there
are 4 color-sets for 8 vsprites, exactly matching the
hardware maximum capabilities.
********************************************************************* */
nextlines = (WORD *)AllocMem(sizeof(WORD) * 8,
MEMF_PUBLIC);
if(nextlines == NULL)
printf("\nNo memory for nextlines\n");
/* The nextlines array is used to hold system information about
"at which line number on the screen is this hardware sprite
again going to become available to be given a new vsprite to
display".
*/
collHandler = (struct collTable *)AllocMem(sizeof(struct collTable),
MEMF_PUBLIC);
if(collHandler == NULL)
printf("\nNo memory for collHandler\n");
g->nextLine = nextlines;
g->lastColor = lastcolors;
g->collHandler = collHandler;
g->leftmost = 0;
g->rightmost = r->BitMap->BytesPerRow * 8 - 1;
g->topmost = 0;
g->bottommost = r->BitMap->Rows - 1;
/* when any part of the object touches or passes across
this boundary, it will cause the boundary collision
routine to be called. This is at smash[0] in the
collision handler table and is called only if
DoCollision is called. */
g->sprRsrvd = 0xff;
/* by setting all 1 bits here, it means that there are NO
reserved sprites. The system can freely use all of the
hardware sprites for its own purposes. The user is not
trying to independently use any hardware sprites. */
printf("\nGoing to Link rastport and gelsinfo now\n");
r->GelsInfo = g; /* link together the two structures */
return;
}
/* This routine cannot be run until the first LoadView(&view) has been
executed. InitGels works with an already active View, so LoadView
must have been run first */
NewGelList(myGels)
struct GelsInfo *myGels;
{
struct VSprite *dumSpriteOne =
(struct VSprite *)AllocMem(sizeof(struct VSprite),
MEMF_PUBLIC+MEMF_CLEAR);
struct VSprite *dumSpriteTwo =
(struct VSprite *)AllocMem(sizeof(struct VSprite),
MEMF_PUBLIC+MEMF_CLEAR);
InitGels( dumSpriteOne, dumSpriteTwo, myGels ); /* changed from V23 */
/* pointers initialized to the dummy sprites which will be
used by the system to keep track of the animation system */
return;
}
/* use this to get rid of the gels stuff when it is not needed any more */
/* you MUST have allocated the gels info stuff with the routines NewGelList
and ReadyGels */
PurgeGels(g)
struct GelsInfo *g;
{
FreeMem(g->lastColor, sizeof(LONG) * 8);
FreeMem(g->nextLine, sizeof(WORD) * 8);
FreeMem(g->collHandler, sizeof(struct collTable));
FreeMem(g->gelHead, sizeof(struct VSprite));
FreeMem(g->gelTail, sizeof(struct VSprite));
}
/* MakeVSprite only creates the vsprite,it doesnt add it to the system list. */
/* (reason it isnt added is that this routine is also used by MakeBob) */
/* user must do AddVSprite after it is created. */
struct VSprite *MakeVSprite(lineheight,image,colorset,x,y,
width,imagedepth,flags)
SHORT lineheight; /* how tall is this vsprite? */
WORD *image; /* where is the vsprite image data, should be
twice as many words as the value of lineheight */
WORD *colorset; /* where is the set of three words which describes
the colors that this vsprite can take on? */
SHORT x,y; /* what is its initial onscreen position? */
SHORT width, imagedepth,flags;
{
struct VSprite *v; /* make a pointer to the vsprite structure which
this routine dynamically allocates */
v = (struct VSprite *)AllocMem(sizeof(struct VSprite),MEMF_PUBLIC+MEMF_CLEAR);
v->X = x; /* establish initial position relative to
the Display coordinates */
v->Y = y;
v->Flags = flags; /* is this a vsprite, not a bob? */
v->Height = lineheight; /* user says how high it is */
v->Width = width; /* a vsprite is always 1 word (16 bits) wide */
v->Depth = imagedepth; /* a vsprite is always 2 planes deep but if
its being used to make a bob, it may
be deeper .....
There are two kinds of depth... the
depth of the image itself, and the
depth of the playfield into which it
will be drawn. The image depth says
how much data space will be needed to
store an image if dynamically allocated.
The playfield depth establishes how
much space will be needed to save and
restore the background when a bob is
drawn */
v->MeMask = 1; /* assume that user at least has a default
boundary collision routine.... bit 1 of
this mask is reserved for boundary
collision detect during DoCollision(); */
v->HitMask = 1; /* assume that user at least has a default
boundary collision routine.... bit 1 of
this mask is reserved for boundary
collision detect during DoCollision(); */
v->ImageData = image; /* user says where to find the image */
v->SprColors = colorset; /* user says where to find its colors */
v->PlanePick = 0x01;
v->PlaneOnOff = 0x00;
v->BorderLine = (WORD *)AllocMem((sizeof(WORD)*width),MEMF_PUBLIC);
/* show system where to find a mask which is a squished down version
of the vsprite (allows for fast horizontal border collision detect */
v->CollMask = (WORD *)AllocMem(sizeof(WORD) * lineheight * width,
MEMF_PUBLIC);
/* show system where to find the mask which contains a 1 bit
for any position in the object in any plane where there
is a 1 bit (all planes OR'ed together) */
InitMasks(v); /* create the collMask and borderLine */
return(v);
}
/* deallocate memory which has been allocated by the routine MakeVSprite */
DeleteVSprite( v )
struct VSprite *v;
{
FreeMem(v->BorderLine, sizeof(WORD));
FreeMem(v->CollMask, sizeof(WORD) * v->Height);
FreeMem(v, sizeof(struct VSprite));
return;
}
struct Bob *MakeBob(bitwidth,lineheight,imagedepth,image,pfdepth,
planePick,planeOnOff, x,y)
SHORT bitwidth,lineheight,imagedepth,planePick,planeOnOff,x,y,pfdepth;
WORD *image;
{
struct Bob *b;
struct VSprite *v;
SHORT flags;
SHORT wordwidth;
wordwidth = (bitwidth+15)/16;
flags = SAVEBACK | OVERLAY;
v = MakeVSprite(lineheight,image,NULL,x,y,wordwidth,imagedepth,flags);
/* no color set for bobs */
/* create a vsprite for this bob, will have to be deleted
later (freed) when this bob gets deleted */
b = (struct Bob *)AllocMem(sizeof(struct Bob),MEMF_PUBLIC);
v->SprColors = 0; /* bobs dont get colorsets */
v->PlanePick = planePick; /* user selects which bit planes
into which the image is to be
drawn */
v->PlaneOnOff = planeOnOff; /* what happens to the bit planes
into which the image is not
drawn. User selected */
v->VSBob = b; /* link together the bob and its vsprite structures */
b->BobVSprite = v;
/* InitMasks does not preset the imageShadow ... user
can select to use the collMask or to create his
own version of a shadow (usually the same). */
b->ImageShadow = v->CollMask;
b->SaveBuffer = (WORD *)AllocMem((lineheight*(wordwidth * 2) * pfdepth),
MEMF_PUBLIC);
/* tell where to save background */
/* must have enough space for as many bitplanes deep as
the display into which everything is being drawn */
b->Before = 0; /* when bob first is made, we wont care about priority */
b->After = 0;
/* interbob priorities are set such that the earliest defined bobs have
the lowest priority, last bob defined is on top */
b->Flags = 0; /* not part of an animation (BOBISCOMP) and dont keep the
image present after bob is removed (SAVEBOB) */
b->BobComp = 0; /* this is not part of an animation */
b->DBuffer = 0; /* this is not double buffered */
return(b); /* return a pointer to this newly created bob for additional
user interaction or for AddBob(b); */
}
/* deallocate memory which has been allocated by the routine MakeBob */
DeleteBob( b, pfdepth )
struct Bob *b;
SHORT pfdepth;
{
DeleteVSprite(b->BobVSprite);
FreeMem( b->SaveBuffer,(b->BobVSprite->Height*(b->BobVSprite->Width * 2) * pfdepth));
FreeMem( b, sizeof(struct Bob));
return;
}
/* geltools.c */
/* NOTE: don't try to use vsprites until system software V1.1 becomes
available. This tool works to do bobs, but not vsprites until 1.1.
(system bug corrected).
*/
/*
author: Rob Peck 9/85. Will eventually cover AnimObs and AnimComps
but not yet.
also note that NewGelList can be merged directly into
ReadyGels (next version will do so). No need to have
separate.
*/
/* ***********************************************************************
this file is a collection of tools which are used with the vsprite and
bob software. It contains the following:
ReadyGels( *gelsinfo, *rastport )
NewGelList( *gelsinfo )
PurgeGels( *gelsinfo )
struct Bob MakeBob(bitwidth,lineheight,imagedepth,*image,pfdepth,
planePick,planeOnOff,x,y)
DeleteBob( &Bob );
struct VSprite MakeVSprite(lineheight,*image,*colorset,x,y,
width,imagedepth,flags);
DeleteVSprite( &VSprite );
ReadyGels sets up the defaults of the gel system by initializing the
GelsInfo structure you provide. It uses information in your
RastPort structure to establish boundary collision defaults at
the outer edges of the raster. It also links together the
GelsInfo and the RastPort which you provide.
NewGelList allocates space for two dummy virtual sprite structures
and calls InitGels. You must already have run LoadView and
ReadyGels before NewGelList is called.
PurgeGels deallocates all memory which ReadyGels and NewGelList have
allocated. The system will crash if you have not used these
routines to allocate the space (you cant deallocate something
which you havent allocated in the first place).
MakeVSprite allocates enough space for and inits a normal vsprite.
DeleteVSprite deallocates the memory it used.
MakeBob initializes a standard bob and allocates as much memory as is needed
for a normal bob and its vsprite structure, links them together.
To find the associated vsprite, look at the back-pointer (see the
routine doc itself).
DeleteBob deallocates the memory it used.
******************************************************************* */
/* user passes a pointer to his GelsInfo structure which he wants to init,
along with a pointer to his IVPArgs. Default init places the topmost
bottommost etc at the outermost boundaries of the users rastport parameters
*/
ReadyGels(g, r)
struct RastPort *r;
struct GelsInfo *g;
{
WORD *lastcolors; /* pointer to an array of 8 pointers to the last
colors assigned to a hardware sprite */
WORD *nextlines; /* pointer to an array of 8 words which are used
to keep track of the last lines of each sprite */
struct CollTable *collHandler;
/* pointer to the collision handler table */
/* this is a table of pointers to the routines which should
be performed when DoCollision senses a collision. This
declaration may not be necessary for a basic vsprite with
no collision detection implemented, but then it makes for
a complete example */
printf("\nEntered ReadyGels\n");
lastcolors = (WORD *)AllocMem(sizeof(LONG) * 8,
MEMF_PUBLIC+MEMF_CLEAR);
if(lastcolors == NULL)
printf("\nNo memory for lastcolors\n");
/* *******************************************************************
In the lastcolors pointer array, the system will store
a pointer to the color definitions most recently used
by the system. .... as a reminder, virtual sprites can
be assigned to any of the real hardware sprites which
may be available at the time. The vsprite colors will
be written into the hardware sprite register set for
the hardware sprite to which that vsprite is assigned.
This pointer array contains one pointer to the last
set of three colors (from the vsprite structure *sprColors)
for each hardware sprite.
As the system is scanning to determine which hardware
sprite should next be used to represent a vsprite, it
checks the contents of this array. If a hardware sprite
is available and already has been assigned this set of
colors, no color assignment is needed, and therefore
no color change instructions will be generated for the
copper list.
If all vsprites use a different set of sprColors, (pointers
to sprColors are different for all vsprites), then there
is a limit of 4 vsprites on a horizontal line. If, on
the other hand, you define, lets say 8 vsprites, with
1 and 2 having the same sprColors, 3 and 4 the same as
each other, 5 and 6 the same as each other, and 7 and 8
also having the same vsprite colors, then you will be
able to have all 8 vsprites on the same horizontal line.
In this case, you will be able to put all 8 vsprites on
the same horizontal line. The reason this helps is that
the system hardware shares the color registers between pairs
of hardware sprites. The system thus has enough resources
to assign all vsprites to hardware sprites in that there
are 4 color-sets for 8 vsprites, exactly matching the
hardware maximum capabilities.
********************************************************************* */
nextlines = (WORD *)AllocMem(sizeof(WORD) * 8,
MEMF_PUBLIC);
if(nextlines == NULL)
printf("\nNo memory for nextlines\n");
/* The nextlines array is used to hold system information about
"at which line number on the screen is this hardware sprite
again going to become available to be given a new vsprite to
display".
*/
collHandler = (struct collTable *)AllocMem(sizeof(struct collTable),
MEMF_PUBLIC);
if(collHandler == NULL)
printf("\nNo memory for collHandler\n");
g->nextLine = nextlines;
g->lastColor = lastcolors;
g->collHandler = collHandler;
g->leftmost = 0;
g->rightmost = r->BitMap->BytesPerRow * 8 - 1;
g->topmost = 0;
g->bottommost = r->BitMap->Rows - 1;
/* when any part of the object touches or passes across
this boundary, it will cause the boundary collision
routine to be called. This is at smash[0] in the
collision handler table and is called only if
DoCollision is called. */
g->sprRsrvd = 0xff;
/* by setting all 1 bits here, it means that there are NO
reserved sprites. The system can freely use all of the
hardware sprites for its own purposes. The user is not
trying to independently use any hardware sprites. */
printf("\nGoing to Link rastport and gelsinfo now\n");
r->GelsInfo = g; /* link together the two structures */
return;
}
/* This routine cannot be run until the first LoadView(&view) has been
executed. InitGels works with an already active View, so LoadView
must have been run first */
NewGelList(myGels)
struct GelsInfo *myGels;
{
struct VSprite *dumSpriteOne =
(struct VSprite *)AllocMem(sizeof(struct VSprite),
MEMF_PUBLIC+MEMF_CLEAR);
struct VSprite *dumSpriteTwo =
(struct VSprite *)AllocMem(sizeof(struct VSprite),
MEMF_PUBLIC+MEMF_CLEAR);
InitGels( dumSpriteOne, dumSpriteTwo, myGels ); /* changed from V23 */
/* pointers initialized to the dummy sprites which will be
used by the system to keep track of the animation system */
return;
}
/* use this to get rid of the gels stuff when it is not needed any more */
/* you MUST have allocated the gels info stuff with the routines NewGelList
and ReadyGels */
PurgeGels(g)
struct GelsInfo *g;
{
FreeMem(g->lastColor, sizeof(LONG) * 8);
FreeMem(g->nextLine, sizeof(WORD) * 8);
FreeMem(g->collHandler, sizeof(struct collTable));
FreeMem(g->gelHead, sizeof(struct VSprite));
FreeMem(g->gelTail, sizeof(struct VSprite));
}
/* MakeVSprite only creates the vsprite,it doesnt add it to the system list. */
/* (reason it isnt added is that this routine is also used by MakeBob) */
/* user must do AddVSprite after it is created. */
struct VSprite *MakeVSprite(lineheight,image,colorset,x,y,
width,imagedepth,flags)
SHORT lineheight; /* how tall is this vsprite? */
WORD *image; /* where is the vsprite image data, should be
twice as many words as the value of lineheight */
WORD *colorset; /* where is the set of three words which describes
the colors that this vsprite can take on? */
SHORT x,y; /* what is its initial onscreen position? */
SHORT width, imagedepth,flags;
{
struct VSprite *v; /* make a pointer to the vsprite structure which
this routine dynamically allocates */
v = (struct VSprite *)AllocMem(sizeof(struct VSprite),MEMF_PUBLIC+MEMF_CLEAR);
v->X = x; /* establish initial position relative to
the Display coordinates */
v->Y = y;
v->Flags = flags; /* is this a vsprite, not a bob? */
v->Height = lineheight; /* user says how high it is */
v->Width = width; /* a vsprite is always 1 word (16 bits) wide */
v->Depth = imagedepth; /* a vsprite is always 2 planes deep but if
its being used to make a bob, it may
be deeper .....
There are two kinds of depth... the
depth of the image itself, and the
depth of the playfield into which it
will be drawn. The image depth says
how much data space will be needed to
store an image if dynamically allocated.
The playfield depth establishes how
much space will be needed to save and
restore the background when a bob is
drawn */